package com.pai4j.pgc.service.behavior;

import com.pai4j.common.util.SpringContextUtil;
import com.pai4j.pgc.dao.community.IResourceBehaviorDAO;
import com.pai4j.pgc.entity.community.ResourceBehaviorEntity;

/***
 * 资源行为服务 - 写 (单向：没有取消行为，点击、浏览)
 */
public class ResourceOneWayBehaviorService extends AbstractResourceBehaviorService {

    @Override
    public boolean behaviorResource(String userId, Long resourceIndex, String resourceType, String behaviorType) {
        IResourceBehaviorDAO resourceBehaviorDAO = SpringContextUtil.getBean(IResourceBehaviorDAO.class);
        ResourceBehaviorEntity behaviorEntity = new ResourceBehaviorEntity();
        behaviorEntity.setUserId(userId);
        behaviorEntity.setResourceIndex(resourceIndex);
        behaviorEntity.setResourceType(resourceType);
        behaviorEntity.setBehaviorType(behaviorType);
        behaviorEntity.setStatus(Boolean.TRUE);
        resourceBehaviorDAO.save(behaviorEntity);
        // 刷新缓存
        return true;
    }
}
